.PHONY: help up down logs shell migrate test test-clean env ui-install ui-start ui-dev ui-build ui-dev-start up-api up-ui down-api down-ui

# Default target
help:
	@echo "Available commands:"
	@echo "  make env       - Copy .env.example to .env"
	@echo "  make up        - Start all containers"
	@echo "  make up api    - Start API service and dependencies"
	@echo "  make up ui     - Start UI service only"
	@echo "  make down      - Stop all containers"
	@echo "  make down api  - Stop API service"
	@echo "  make down ui   - Stop UI service"
	@echo "  make logs      - Show container logs"
	@echo "  make shell     - Open a shell in the api container"
	@echo "  make migrate   - Run database migrations"
	@echo "  make test      - Run tests in a new container"
	@echo "  make test-clean - Run tests and clean up volumes"
	@echo "  make ui-install - Install frontend dependencies"
	@echo "  make ui-start  - Start the frontend development server"
	@echo "  make ui-dev    - Install dependencies and start the frontend in dev mode"
	@echo "  make ui        - Install dependencies and start the frontend in production mode"

env:
	cd api && cp .env.example .env
	cd ui && cp .env.example .env

build:
	docker compose build

up:
	# Bugfix: docker compose配置文件已经指明了.env文件作为环境配置项，不应当在这里画蛇添足
	docker compose up -d

up-api:
	docker compose up -d mem0_store openmemory-mcp

up-ui:
	docker compose up -d openmemory-ui

down:
	docker compose down -v
	rm -f api/openmemory.db

down-api:
	docker compose stop openmemory-mcp mem0_store
	rm -f api/openmemory.db

down-ui:
	docker compose stop openmemory-ui

logs:
	docker compose logs -f

shell:
	docker compose exec openmemory-mcp bash

upgrade:
	docker compose exec openmemory-mcp alembic upgrade head

migrate:
	docker compose exec openmemory-mcp alembic upgrade head

downgrade:
	docker compose exec openmemory-mcp alembic downgrade -1

ui-dev:
	cd ui && pnpm install && pnpm dev
